package gxnu.edu.cn.mapper;

import gxnu.edu.cn.entity.Cpasswordrest;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import gxnu.edu.cn.entity.PasswordRest;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;

/**
 * <p>
 * 口令重置验证表 Mapper 接口
 * </p>
 *
 * @author cq
 * @since 2025-05-07
 */
@Mapper
public interface CpasswordrestMapper extends BaseMapper<Cpasswordrest> {

        @Insert("insert into cpasswordrest(userName,validUntil,verificationCode) values(#{userName},#{validUntil},#{verificationCode})")
        public void insert(PasswordRest passwordRest);

        @Update("update cpasswordrest set status = 0 where userName = #{userName} and status = 1")
        void updateStatusByUserName(String userName);

        @Select("select count(*) from cpasswordrest where userName = #{userName} and verificationCode = #{verificationCode} and validUntil >= #{now} and status = 1")
        int validEmailCode( String userName,
                            LocalDateTime now,
                            String verificationCode);
    }


